#include "pintaros.h"

int main()
{

  /**
   * @brief Initialize everything
   */
  HALInitialize();
  FSInitialize();
  stateInitialize();
  transInitialize();

  /**
   * @brief Send ATR (Answer to Reset)
   */
  sendATR();

  /**
   * @brief Main Loop
   */
  while(1) {

    /**
     * @brief wait for command header (5 byte)
     */
    while(rx_buffer.length<5);

    /**
     * @brief call command Interpreter which call command handler
     */
    commandInterpreter(&rx_buffer, &apdu_res);

    /**
     * @brief call response Manager which 
     */
    responseManager(&tx_buffer, &apdu_res);

    /**
     * @brief send the tx buffer
     */
    transTx(&tx_buffer);

    /**
     * @brief empty the rx buffer
     */
    rx_buffer.length = 0;
  }

}
